package com.liuzu.esys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liuzu.esys.common.LayuiPageVo;

import com.liuzu.esys.mapper.OperateMapper;
import com.liuzu.esys.pojo.Operate;
import com.liuzu.esys.service.OperateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("operateService")
public class OperateServiceImpl implements OperateService {

    @Autowired
    private OperateMapper operateMapper;

    @Override
    public LayuiPageVo<Operate> operatePageData(Map<String, Object> params) {
        Integer page = Integer.parseInt(params.get("page") + "");
        Integer limit = Integer.parseInt(params.get("limit") + "");
        PageHelper.startPage(page,limit);
        List<Operate> operates = operateMapper.selectByParams(params);
        PageInfo<Operate> operatePageInfo = new PageInfo<>(operates);
        LayuiPageVo<Operate> operateLayuiPageVo = new LayuiPageVo<>();
        operateLayuiPageVo.setCode(0);
        operateLayuiPageVo.setMsg("分页列表数据");
        operateLayuiPageVo.setCount(operatePageInfo.getTotal());
        operateLayuiPageVo.setData(operatePageInfo.getList());
        return operateLayuiPageVo;
    }

    @Override
    public int addOperate(Operate operate) {
        int i = operateMapper.addOperate(operate);
        return i;
    }

    @Override
    public int updateOperate(Operate operate) {
        return operateMapper.updateOperateByKey(operate);
    }

    @Override
    public int deleteOperate(Integer id) {
        return operateMapper.deleteOperateByKey(id);
    }

    @Override
    public int deleteOperateByIds(String ids) {
        String[] arrId = ids.split(",");
        return operateMapper.deleteOperateByIds(arrId);
    }
}
